<template>
  <div class="pagss">
    <div style="height: 20px;"></div>
    <Navvz></Navvz>
    <el-row class="center" style="margin-top: 60px;">
      <el-col :span="24">
        <div class="panel-group1">
          <el-form label-width="100px" class="demo-ruleForm">

            <el-form-item style="width: 300px;" label="用户名：">
              <div class="row_a_c">
                <el-input v-model="username"></el-input>
                <div style="width: 60px;margin-left: 18px;" class="color_1A82FB f_14 cursor" @click="updateUser()">修改
                </div>
              </div>
            </el-form-item>

            <el-form-item style="width: 300px;" label="登录密码：">
              <div class="row_a_c">
                <el-input v-model="password"></el-input>
                <div style="width: 60px;margin-left: 18px;" class="color_1A82FB f_14 cursor" @click="updateUser(2)">修改
                </div>
              </div>
            </el-form-item>

            <el-form-item style="width: 300px;" label="修改头像：">

              <el-upload :action="upload_url" :headers="headers" :before-upload="handleSetHeaders"
                :on-success="handleFileSuccess" :show-file-list="false" class="avatar-uploader">

                <div class="row center" style="position: relative;">
                  <div>
                    <div class="tximg column center">
                      <img style="height: 78px;width: 90px;" v-if="avatar" :src="avatar" class="avatar">
                      <img v-else style="height: 78px;width: 90px;" src="@/assets/images/tx.png" />
                      <div class="mt_5 f_14 color_878787">上传头像</div>
                    </div>


                    <div class="mt_5" style="width: 260px;">(支持200kb以下的JPG、PNG格式的图片)</div>
                  </div>

                  <div style="position: absolute;left: 180px;" class="cursor">
                    <el-button type="primary" @click.stop="updateUser()">保存头像</el-button>
                  </div>

                </div>

              </el-upload>
            </el-form-item>


            <el-form-item style="width: 300px;" label="提现银行：" prop="bank">
              <div class=" space-between center yhbox">
                <div>
                  <img style="width: 20px;height: 20px;" src="@/assets/images/yy.png" />
                </div>

                <div class="column center">
                  <div class="row center">
                    <div class="row center">
                      <img style="width: 40px;height: 40px;" :src="open_bank_log" />
                    </div>

                    <div class="column ml_10">
                      <div class="f_16 f_bold" style="line-height: 16px;letter-spacing:11px">{{open_bank}}</div>
                      <div class="" style="width: 146px;line-height: 12px;margin-top: 5px;font-size: 8px;">
                        {{open_bank_e}}
                      </div>
                    </div>
                  </div>
                  <div class="f_bold"> {{card_number}}</div>
                </div>
                <div>
                </div>
              </div>
            </el-form-item>


            <!--            <el-form-item style="width: 300px;" label="真实姓名：">
              <div class="row_a_c">
                <el-input v-model="real_name"></el-input>
                <div style="width: 60px;margin-left: 18px;" class="color_1A82FB f_14 cursor" @click="updateUser()">修改
                </div>
              </div>
            </el-form-item> -->


            <el-form-item style="width: 300px;" label="全安密码：">
              <div class="row_a_c">
                <el-input v-model="safe_password"></el-input>
                <div style="width: 60px;margin-left: 18px;" class="color_1A82FB f_14 cursor"
                  @click="updateSafePassword(bank_id)">修改
                </div>
              </div>
            </el-form-item>



            <el-form-item style="width: 300px;" label="手机绑定：">
              <div class="row_a_c">
                <el-input v-model="mobile"></el-input>
                <div style="width: 60px;margin-left: 18px;" class="color_1A82FB f_14 cursor" @click="updateUser()">修改
                </div>
              </div>
            </el-form-item>


            <el-form-item style="width: 300px;" label="QQ绑定：">
              <div class="row_a_c">
                <el-input v-model="qq"></el-input>
                <div style="width: 60px;margin-left: 18px;" class="color_1A82FB f_14 cursor" @click="updateUser()">修改
                </div>
              </div>
            </el-form-item>


            <el-form-item style="width: 300px;" label="微信绑定">
              <div class="row_a_c">
                <el-input v-model="weixin"></el-input>
                <div style="width: 60px;margin-left: 18px;" class="color_1A82FB f_14 cursor" @click="updateUser()">修改
                </div>
              </div>
            </el-form-item>

          </el-form>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import CountTo from 'vue-count-to'
  import Cookies from 'js-cookie'
  import Vue from 'vue';
  import Navvz from "@/components/Navvz";
  import Sidebartss from "@/components/Sidebartss";
  import * as User from "@/api/system/user";
  import * as Auth from '@/utils/auth'

  export default {
    username: 'Index',
    components: {
      CountTo,
      Navvz,
      Sidebartss

    },
    data() {
      return {
        password: '', //登录密码
        avatar: '',
        username: '',
        mobile: '',
        qq: '',
        weixin: '',
        real_name: '',

        safe_password: '',
        bank_id: '', //银行卡id

        open_bank_log: '',
        open_bank: '',
        open_bank_e: '',
        card_number: '',

        upload_url: process.env.VUE_APP_BASE_URL + "/file/upload",
        headers: Auth.getHeader(),
      }
    },
    created() {
      this.getUserInfo(); //查询用户详情
      // this.getUserBank(); //查询用户银行卡
    },
    mounted() {

    },
    methods: {

      /**查询用户银行卡 */
      getUserBank() {

        this.loading = true;
        User.getUserBank().then(response => {
          this.open_bank_log = response.data.open_bank_log
          this.open_bank = response.data.open_bank
          this.open_bank_e = response.data.open_bank_e
          this.card_number = response.data.card_number
          this.bank_id = response.data.id
          console.log('银行卡', response.data)
          this.loading = false;
        });
      },


      /**查询用户详情 */
      getUserInfo() {
        //audit_status 1：未提交，2：已提交 3：审核通过 4：审核失败'
        this.loading = true;
        User.getUserInfo().then(response => {

          this.avatar = response.data.avatar
          this.username = response.data.username
          this.mobile = response.data.mobile
          this.qq = response.data.qq
          this.weixin = response.data.weixin
          this.real_name = response.data.real_name
          
          this.open_bank_log = response.data.open_bank_log
          this.open_bank = response.data.open_bank
          this.open_bank_e = response.data.open_bank_e
          this.card_number = response.data.card_number


          console.log('用户详情', response.data)
          this.loading = false;
        });
      },

      /**修改安全密码*/
      updateSafePassword(id) {

        if (!this.safe_password) {
          this.$message({
            message: '安全密码不能为空',
            type: 'warning'
          });
          return
        }
        if (this.safe_password.length < 8) {
          this.$message({
            message: '安全密码不能小于8位',
            type: 'warning'
          });
          return
        }

        var per = {
          id: id,
          safe_password: this.safe_password
        }

        User.updateSafePassword(per).then((data) => {
          this.$modal.msgSuccess("修改成功");
          //处理成功后的逻辑
          console.log(data); //这个data 是接收的resolve参数--
        }).catch((err) => {
          console.log(err);
        })
      },


      handleSetHeaders() {
        this.headers = Auth.getHeader();
      },
      /****文件上传*****/
      handleFileSuccess(res) {
        this.avatar = res.data;
      },




      updateUser(type=1) {

       if(type==2){
         if (!this.password) {
           this.$message({
             message: '登录密码不能为空',
             type: 'warning'
           });
           return
         }

         if (this.password.length<8) {
           this.$message({
             message: '登录密码不能小于8位',
             type: 'warning'
           });
           return
         }
       }

        if (!this.username) {
          this.$message({
            message: '用户名不能为空',
            type: 'warning'
          });
          return

        }
        if (!this.mobile) {
          this.$message({
            message: '手机号不能为空',
            type: 'warning'
          });
          return
        }

        var per = {
          avatar: this.avatar,
          username: this.username,
          mobile: this.mobile,
          qq: this.qq,
          weixin: this.weixin,
        }
        if (this.password) {
          per.password = this.password
        }

        User.updateUser(per).then((data) => {
          this.$modal.msgSuccess("修改成功");
          //处理成功后的逻辑
          console.log(data); //这个data 是接收的resolve参数--
        }).catch((err) => {
          console.log(err);
        })
      },


      toUrl(url) {
        console.log(111)
        this.$router.push(url);
      },



    }
  }
</script>

<style lang="scss" scoped>
  .pagss {
    height: 100%;
    background: #E4EEF9;
    // padding: 5px 0 15px 40px;
  }

  .yhbox {
    padding: 20px;
    width: 320px;
    height: 120px;
    background: #FFFFFF;
    // background: red;
    border-radius: 4px 4px 4px 4px;
    opacity: 1;
    border: 1px solid #BBBBBB;
  }

  .panel-group1 {
    padding: 25px;
    margin-top: -50px;
    margin-bottom: 0px;
    margin-right: 15px;
    margin-left: 15px;
    min-height: 760px;
    background: #FFFFFF;
    border-radius: 10px 10px 10px 10px;
    box-shadow: 1px 5px 9px 1px rgba(180, 185, 242, 0.68);
    opacity: 1;
  }

  ::v-deep .el-button--primary {
      color: #FFFFFF;
      background-color: #3FC1C9 !important;
      border-color: #3FC1C9 !important;
  }

    ::v-deep .el-button:hover,
    .el-button:focus {
      color: #000000;
      border-color: #A5EDF1;
      background-color: #A5EDF1;
    }

  .tximg {
    width: 150px;
    height: 150px;
    background: #FFFFFF;
    border-radius: 4px 4px 4px 4px;
    opacity: 1;
    border: 1px solid #BBBBBB;
  }
</style>
